<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单体架构中的本地事务失效场景</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .number-circle {
            width: 48px;
            height: 48px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            font-weight: 700;
            font-size: 1.25rem;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.25rem;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .fade-in {
            animation: fadeIn 0.8s ease-out;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #667eea;
            font-size: 1.5rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-white">
        <div class="absolute inset-0 bg-gradient-to-br from-purple-50 via-white to-blue-50"></div>
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24">
            <div class="text-center fade-in">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    <span class="gradient-text">单体架构中的</span><br>
                    <span class="text-gray-900">本地事务失效场景</span>
                </h1>
                <p class="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
                    <span class="drop-cap serif-font">在</span>单体架构中，本地事务通常是由数据库管理系统（DBMS）在单个数据库连接上进行管理的，因此它们能够很好地保证数据的一致性。然而，在某些特定情况下，本地事务可能会失效，导致数据不一致或者事务无法正确提交。
                </p>
            </div>
        </div>
    </section>

    <!-- Visual Overview -->
    <section class="py-16 bg-white">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-900 mb-4">事务失效场景概览</h2>
                <p class="text-lg text-gray-600">九大常见场景的关系图谱</p>
            </div>
            <div class="bg-gray-50 rounded-2xl p-8 shadow-lg">
                <div class="mermaid">
                    graph TD
                        A[本地事务失效] --> B[事务管理问题]
                        A --> C[连接与资源问题]
                        A --> D[并发与隔离问题]
                        
                        B --> B1[嵌套事务管理]
                        B --> B2[异常处理不当]
                        B --> B3[手动管理边界]
                        B --> B4[配置错误]
                        
                        C --> C1[数据库连接失效]
                        C --> C2[超时设置]
                        C --> C3[分布式操作]
                        
                        D --> D1[数据库锁定]
                        D --> D2[隔离级别错误]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                        style B fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                        style C fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                        style D fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="grid gap-8 md:grid-cols-2 lg:grid-cols-3">
                
                <!-- Card 1 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">1</div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-900 mb-2">嵌套事务或多层事务管理</h3>
                            <div class="icon-box mb-4">
                                <i class="fas fa-layer-group"></i>
                            </div>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i>问题</h4>
                            <p class="text-gray-600">当多个事务嵌套使用，且不同层次的事务管理器没有正确协调时，可能会导致事务边界混乱，最终影响事务的一致性。例如，外层事务已经提交，而内层事务却回滚了，这会导致数据不一致。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>原因</h4>
                            <p class="text-gray-600">不同的事务管理器使用不同的事务边界，可能导致部分事务没有被正确提交或回滚。</p>
                        </div>
                    </div>
                </div>

                <!-- Card 2 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">2</div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-900 mb-2">未正确捕获异常</h3>
                            <div class="icon-box mb-4">
                                <i class="fas fa-bug"></i>
                            </div>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i>问题</h4>
                            <p class="text-gray-600">在代码中，未正确捕获和处理异常会导致事务在出现错误时未能正确回滚。例如，某些RuntimeException未被捕获到，事务管理器并未意识到事务需要回滚。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>原因</h4>
                            <p class="text-gray-600">事务管理器依赖于异常来决定是否回滚事务。如果异常未被捕获或处理不当，事务可能被错误地提交。</p>
                        </div>
                    </div>
                </div>

                <!-- Card 3 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">3</div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-900 mb-2">数据库连接的失效</h3>
                            <div class="icon-box mb-4">
                                <i class="fas fa-unlink"></i>
                            </div>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i>问题</h4>
                            <p class="text-gray-600">如果事务进行中，数据库连接由于网络问题、数据库宕机等原因突然失效，可能导致事务无法提交或回滚。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>原因</h4>
                            <p class="text-gray-600">数据库连接失效后，事务可能处于不确定状态（例如，部分提交）。这会导致数据不一致或数据丢失。</p>
                        </div>
                    </div>
                </div>

                <!-- Card 4 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">4</div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-900 mb-2">超时设置</h3>
                            <div class="icon-box mb-4">
                                <i class="fas fa-clock"></i>
                            </div>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i>问题</h4>
                            <p class="text-gray-600">事务超时设置过短，导致事务在未完成前就被强制回滚。这种情况在处理大批量数据或复杂操作时尤为常见。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>原因</h4>
                            <p class="text-gray-600">事务超时策略可能会在后台强制回滚未完成的事务，导致数据不一致。</p>
                        </div>
                    </div>
                </div>

                <!-- Card 5 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">5</div>
                        <div>
                            <h3 class="text-xl font-bold text-gray-900 mb-2">手动管理事务边界</h3>
                            <div class="icon-box mb-4">
                                <i class="fas fa-hand-paper"></i>
                            </div>
                        </div>
                    </div>
                    <div class="space-y-4">
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-exclamation-circle text-red-500 mr-2"></i>问题</h4>
                            <p class="text-gray-600">开发人员手动管理事务边界时，如果忘记提交或回滚事务，可能会导致事务被悬空，最终失效。</p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-700 mb-2"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>原因</h4>
                            <p class="text-gray-600">人为错误或忽略事务提交/回滚，导致事务管理器无法正确管理事务的生命周期。</p>
                        </div>
                    </div>
                </div>

                <!-- Card 6 -->
                <div class="card-hover bg-white rounded-2xl shadow-lg p-8">
                    <div class="flex items-start mb-6">
                        <div class="number-circle mr-4">6</div>
                        <div>